/**
 * 
 */
package com.css.crm.bean;

import java.util.List;

import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.css.crm.utility.ConstantUtil;
import com.css.crm.utility.ResourceUtil;

/**
 * @author AIS
 * 
 */
public class CommonBean {

	private String tableRows = null;

	/** * logger. */
	protected Logger log = LoggerFactory.getLogger(getClass());

	public CommonBean() {
		tableRows = ResourceUtil.getSystemConfig().getProperty(ConstantUtil.SYSTEM_TABLE_ROWS);
	}

	protected Object getRequestParameter(String key) {
		return FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(key);
	}

	public String getTableRows() {
		return tableRows;
	}

	private void processChild(List<?> childList) {
		if (childList == null)
			return;
		for (int i = 0; i < childList.size(); i++) {
			UIComponent component = (UIComponent) childList.get(i);

			if (component instanceof UIInput) {
				((UIInput) component).setSubmittedValue(null);
			}

			List<?> childList2 = component.getChildren();
			processChild(childList2);
		}
	}

	/**
	 * clear page data when button immediate attribute set to true
	 */
	public void clearPageData() {
		FacesContext facesContext = FacesContext.getCurrentInstance();
		UIViewRoot viewRoot = facesContext.getViewRoot();
		List<?> childList = null;
		childList = viewRoot.getChildren();
		processChild(childList);

	}
}
